<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>配置文件编辑器</title>
    <style>
        body {
            display: flex;
            flex-direction: column;
            height: 100vh;
            margin: 0;
            padding: 15px;
            box-sizing: border-box;
        }
        .header {
            margin-bottom: 15px;
        }
        #editor {
            width: 100%;
            flex: 1;
            font-family: monospace;
            resize: none;
        }
    </style>
</head>
<body>
    <div class="header">
        配置文件编辑器：
        <select id="fileSelector">
            <option value="motion.cfg">motion.cfg</option>
            <option value="main.cfg">main.cfg</option>
            <option value="testcase.txt">testcase.txt</option>
            <option value="index.html">index.html</option>
        </select>
        <button onclick="loadFile()">打开</button>
        <button onclick="saveFile()">保存</button>
        <button onclick="downloadFile()">下载</button>
    </div>
    <textarea id="editor"></textarea>
    
    <script>
        async function loadFile() {
            const file = document.getElementById('fileSelector').value;
            const response = await fetch(`/cfg/get?file=${file}`);
            document.getElementById('editor').value = await response.text();
        }
        
        async function saveFile() {
            const file = document.getElementById('fileSelector').value;
            const content = document.getElementById('editor').value;
            
            const response = await fetch(`/cfg/save?file=${file}`, {
                method: 'POST',
                body: content
            });
            
            alert(await response.text());
        }
        
        function downloadFile() {
            const file = document.getElementById('fileSelector').value;
            window.location.href = `/cfg/download?file=${file}`;
        }
    </script>
</body>
</html>